home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir42 / gnudbm14.zip / DBMSEQ.C < prev    next >
C/C++ Source or Header  |  1990-08-24  |  3KB  |  101 lines

  1. /* dbmseq.c - Visit all elements in the database.  This is the NDBM
  2.    interface. */
  3.  
  4. /*  This file is part of GDBM, the GNU data base manager, by Philip A. Nelson.
  5.     Copyright (C) 1990  Free Software Foundation, Inc.
  6.  
  7.     GDBM is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 1, or (at your option)
  10.     any later version.
  11.  
  12.     GDBM is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with GDBM; see the file COPYING.  If not, write to
  19.     the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.     You may contact the author by:
  22.        e-mail:  phil@wwu.edu
  23.       us-mail:  Philip A. Nelson
  24.                 Computer Science Department
  25.                 Western Washington University
  26.                 Bellingham, WA 98226
  27.         phone:  (206) 676-3035
  28.        
  29. *************************************************************************/
  30.  
  31. /*
  32.  * MS-DOS port (c) 1990 by Thorsten Ohl, td12@@ddagsi3.bitnet
  33.  *
  34.  * To this port, the same copying conditions apply as to the
  35.  * original release.
  36.  *
  37.  * IMPORTANT:
  38.  * This file is not identical to the original GNU release!
  39.  * You should have received this code as patch to the official
  40.  * GNU release.
  41.  *
  42.  * MORE IMPORTANT:
  43.  * This port comes with ABSOLUTELY NO WARRANTY.
  44.  *
  45.  * $Header: e:/gnu/gdbm/RCS/dbmseq.c'v 1.4.0.1 90/08/16 09:22:15 tho Exp $
  46.  */
  47.  
  48. #include <stdio.h>
  49. #include <sys/types.h>
  50. #ifndef MSDOS
  51. #include <sys/file.h>
  52. #endif /* not MSDOS */
  53. #include <sys/stat.h>
  54. #include "gdbmdefs.h"
  55. #include "extern.h"
  56.  
  57.  
  58. /* NDBM Start the visit of all keys in the database.  This produces
  59.    something in hash order, not in any sorted order.  DBF is the dbm file
  60.    information pointer. */
  61.  
  62. datum
  63. dbm_firstkey (dbf)
  64.      gdbm_file_info *dbf;
  65. {
  66.   datum ret_val;
  67.  
  68.   /* Free previous dynamic memory, do actual call, and save pointer to new
  69.      memory. */
  70.   ret_val = gdbm_firstkey (dbf);
  71.   if (_gdbm_memory.dptr != NULL) free (_gdbm_memory.dptr);
  72.   _gdbm_memory = ret_val;
  73.  
  74.   /* Return the new value. */
  75.   return ret_val;
  76. }
  77.  
  78.  
  79. /* NDBM Continue visiting all keys.  The next key in the sequence is returned.
  80.    DBF is the file information pointer. */
  81.  
  82. datum
  83. dbm_nextkey (dbf)
  84.      gdbm_file_info *dbf;
  85. {
  86.   datum ret_val;
  87.  
  88.   /* Make sure we have a valid key. */
  89.   if (_gdbm_memory.dptr == NULL)
  90.     return _gdbm_memory;
  91.  
  92.   /* Call gdbm nextkey with the old value. After that, free the old value. */
  93.   ret_val = gdbm_nextkey (dbf,_gdbm_memory);
  94.   if (_gdbm_memory.dptr != NULL) free (_gdbm_memory.dptr);
  95.   _gdbm_memory = ret_val;
  96.  
  97.   /* Return the new value. */
  98.   return ret_val;
  99. }
  100.  
  101.